<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5" lang="zh">
<nav th:fragment="navigationbar(prefixUrl)" class="navbar navbar-expand-lg navbar-light"
     style="background-color: #ffffff;box-shadow: 0 -2px 10px #d0cccc;">
    <div class="container">
        <a class="navbar-brand" th:href="@{/}">我们の社区</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
                <li th:class="${prefixUrl=='index'}?'nav-item active':'nav-item'">
                    <a class="nav-link" th:href="@{/}">首页</a>
                </li>
                <li th:class="${prefixUrl=='blog'}?'nav-item active':'nav-item'">
                    <a class="nav-link" th:href="@{/blog}">文章社区</a>
                </li>
                <li th:class="${prefixUrl=='question'}?'nav-item active':'nav-item'">
                    <a class="nav-link" th:href="@{/question}">问答</a>
                </li>
            </ul>

            <!--搜索框-->
            <form class="form-inline nav-item" method="get" th:action="@{/blog/search}" style="margin-right: 15px">
                <input class="form-control mr-sm-2" type="search" placeholder="少放屁，多百度~~" aria-label="Search" name="condition">
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">搜索</button>
            </form>

            <!--写文章图标-->
            <div sec:authorize="isAuthenticated()">
                <a th:href="@{/blog/write}" class="text-decoration-none">
                    写文章
                    <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-pencil-square" fill="currentColor"
                         xmlns="http://www.w3.org/2000/svg">
                        <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456l-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"></path>
                        <path fill-rule="evenodd"
                              d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"></path>
                    </svg>
                </a>
            </div>

            <!--用户未登录-->
            <div sec:authorize="!isAuthenticated()">
                <div class="nav-item">
                    <a class="btn btn-outline-secondary" th:href="@{/login}">登录</a>
                </div>
            </div>

            <!--用户已登录-->
            <div sec:authorize="isAuthenticated()" class="nav-item">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item dropdown">
                        <a style="color: rgba(0,0,0,.5);text-decoration: none" class="nav-link dropdown-toggle" href="#"
                           id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true"
                           aria-expanded="false">
                            <!--没有头像显示默认-->
                            <span th:if="${session.loginUser.avatar==null || session.loginUser.avatar==''}">
                                <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-person-fill"
                                     fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                    <path fill-rule="evenodd"
                                          d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"></path>
                                </svg>
                                <span sec:authentication="name"></span>
                            </span>
                            <!--用户有头像-->
                            <span th:if="${session.loginUser.avatar!=null && session.loginUser.avatar!=''}">
                                <img style="width: 30px;height:30px;border-radius: 50%;"
                                     th:src="${session.loginUser.avatar}" alt="头像">
                                <span sec:authentication="name"></span>
                            </span>
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item"
                               th:href="'/user/' + ${session.loginUser.getUid()} + '/article'">个人中心</a>
                            <a class="dropdown-item"
                               th:href="'/user/profile/' + ${session.loginUser.getUid()}">我的资料</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" th:href="@{/logout}">退出</a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</nav>
</html>